package cn.boy.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo.State;
import android.widget.Toast;
import cn.boy.home.R;

/**
 * get the state of net
 * @author yankun
 *
 */
public class NetChangeReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {

		ConnectivityManager conMan = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
		State mobile = conMan.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
				.getState();
		State wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
				.getState();
		if (mobile.equals(State.CONNECTED)) {
			System.out.println("---mobile connected---");
		} else if (wifi.equals(State.CONNECTED)) {
			System.out.println("---wifi connected---");
		} else {
			System.out.println("---no net connected---");
			Toast.makeText(context, R.string.no_net, 1).show();
		}
	}

}
